package com.yuanli.cosmeticmirror.persenter;

import androidx.lifecycle.LifecycleOwner;

import com.comenjoysoft.baselibrary.listener.CallbackListener;
import com.comenjoysoft.baselibrary.presenter.BasePresenter;
import com.yuanli.cosmeticmirror.bean.TutorialBean;
import com.yuanli.cosmeticmirror.bean.TutorialTypeBean;
import com.yuanli.cosmeticmirror.model.biz.ITutorialBiz;
import com.yuanli.cosmeticmirror.model.impl.TutorialImpl;
import com.yuanli.cosmeticmirror.model.iview.ITutorialView;

public class TutorialPersenter extends BasePresenter<ITutorialView> {

    private final ITutorialBiz biz;

    public TutorialPersenter(ITutorialView view, LifecycleOwner owner) {
        attachView(view);
        biz = new TutorialImpl(owner);
    }

    public void getTutorialType() {
        biz.getTutorialType(new CallbackListener<TutorialTypeBean>() {
            @Override
            public void success(TutorialTypeBean object) {
                if (object != null) {
                    mView.onTypeSuccess(object);
                } else {
                    mView.error();
                }
            }

            @Override
            public void failed(Object object) {
                mView.error();
            }
        });
    }

    public void getTutorial(String id) {
        biz.getTutorial(id, new CallbackListener<TutorialBean>() {
            @Override
            public void success(TutorialBean object) {
                if (object != null) {
                    mView.onSucess(object);
                } else {
                    mView.error();
                }
            }

            @Override
            public void failed(Object object) {
                mView.error();
            }
        });
    }
}
